Typical HAL DTS use cases for migration ¶
Here are the typical DTS use cases for HAL driver migration.
Use case: Get temperature with software/hardware trigger (polling) ¶
Note
In HAL1, there is no status flag indicating “end of measurement” in polling mode. To detect completion, the user must explicitly enable the “End of measurement” interrupt flag via
__HAL_DTS_ENABLE_IT(...)
and then poll that flag.
In HAL2, this interrupt is enabled automatically by
HAL_DTS_StartSensor(), and the driver uses its flag as a status indicator in
HAL_DTS_PollForSensorTemperature().
Warning:
When using polling mode, do not enable the NVIC interrupt request
DTS_IRQn; only the peripheral interrupt flag is used for polling.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
DTS_HandleTypeDef hdts;
int32_t temp;
hdts.Init.TriggerInput = DTS_TRIGGER_HW_NONE /* DTS_TRIGGER_LPTIMER2 for HW trigger*/;
HAL_DTS_Init(&hdts);
__HAL_DTS_ENABLE_IT(&hdts, DTS_IT_TS1_ITE);
HAL_DTS_Start(&hdts);
__HAL_DTS_GET_FLAG(&hdts, DTS_FLAG_TS1_ITE);
HAL_DTS_GetTemperature(&hdts, &temp);
HAL_DTS_Stop(&hdts);
|
hal_dts_handle_t hDTS;
int32_t temp;
HAL_DTS_Init(&hDTS, HAL_DTS);
hal_dts_config_t cfg = { .reference_clock = HAL_DTS_REFERENCE_CLOCK_PCLK,
.quick_measurement = HAL_DTS_QUICK_MEASUREMENT_DISABLE,
.high_speed_clock_division = 0 };
hal_dts_sensor_config_t sensor_cfg = { .trigger = HAL_DTS_TRIGGER_SOFTWARE, /* HAL_DTS_TRIGGER_LPTIM2_CH1 for HW trigger */
.sampling_time = HAL_DTS_SAMPLING_TIME_1_CYCLE };
HAL_DTS_SetConfig(&hDTS, &cfg);
HAL_DTS_SetConfigSensor(&hDTS, HAL_DTS_SENSOR_1, &sensor_cfg);
HAL_DTS_StartSensor(&hDTS, HAL_DTS_SENSOR_1);
HAL_DTS_PollForSensorTemperature(&hDTS, HAL_DTS_SENSOR_1, 1000);
HAL_DTS_GetSensorTemperature(&hDTS, HAL_DTS_SENSOR_1, &temp);
HAL_DTS_StopSensor(&hDTS, HAL_DTS_SENSOR_1);
|
Key changes ¶
In HAL2,
HAL_DTS_StartSensor()enables the end-of-measurement interrupt flag used byHAL_DTS_PollForSensorTemperature().In polling mode, do not enable
DTS_IRQn; only the peripheral interrupt flag is polled.HAL2 uses per-sensor configuration and per-sensor start/stop APIs.
Use case: Get temperature with software/hardware trigger (interrupt mode) ¶
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
DTS_HandleTypeDef hdts;
hdts.Init.TriggerInput = DTS_TRIGGER_SOFTWARE; /* DTS_TRIGGER_LPTIMER2 for HW trigger*/
HAL_DTS_Init(&hdts);
HAL_DTS_Start_IT(&hdts);
HAL_DTS_GetTemperature(&hdts, &temp);
HAL_DTS_Stop_IT(&hdts);
|
hal_dts_handle_t hDTS;
HAL_DTS_Init(&hDTS, HAL_DTS);
hal_dts_sensor_config_t sensor_cfg;
int32_t temp;
sensor_cfg.trigger = HAL_DTS_TRIGGER_SOFTWARE; /* HAL_DTS_TRIGGER_LPTIM2_CH1 for HW trigger */
sensor_cfg.sampling_time = HAL_DTS_SAMPLING_TIME_1_CYCLE;
HAL_DTS_SetConfigSensor(&hDTS, HAL_DTS_SENSOR_1, &sensor_cfg);
HAL_DTS_StartSensor_IT(&hDTS, HAL_DTS_SENSOR_1);
HAL_DTS_GetSensorTemperature(&hDTS, HAL_DTS_SENSOR_1, &temp);
HAL_DTS_StopSensor_IT(&hDTS, HAL_DTS_SENSOR_1);
|
Key changes ¶
HAL2 uses per-sensor interrupt start/stop APIs (
HAL_DTS_StartSensor_IT()andHAL_DTS_StopSensor_IT()).The HAL2 completion callback is consolidated as
HAL_DTS_CpltCallback.
Related examples in HAL2 ¶
|
Example name |
Brief |
|---|---|
|
example_hal_dts_get_temperature_trigger_hw_it |
Get die temperature using hardware trigger in interrupt (non-blocking) mode. |
Use case: Detect temperature thresholds (non-blocking) ¶
Note
In HAL2, threshold configuration is simplified: use the dedicated API
HAL_DTS_SetSensorThresholds(), which accepts High and Low thresholds directly in degrees Celsius. This replaces the manual calculation required in HAL1.
You can check your reference manual to get the formula used in HAL1 to convert register values to degrees Celsius.
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
DTS_HandleTypeDef hdts;
int32_t temp;
HAL_DTS_Init(&hdts);
hdts.Init.HighThreshold = 100; /* register readable value that needs to be */
hdts.Init.LowThreshold = 10; /* calculated to select the desired threshold in degrees Celsius */
/* For example: Temperature: 40
register writable value: 60
given: ramp coeff (r): 6080, Calibration frequency (r): 1875000Hz, T0: 3D, using LSE: 32000Hz
These values depend on your specific device and configuration, check your reference manual for more details */
HAL_DTS_Start_IT(&hdts);
HAL_DTS_GetTemperature(&hdts, &temp);
HAL_DTS_Stop_IT(&hdts);
|
hal_dts_handle_t hDTS;
int32_t temp;
HAL_DTS_Init(&hDTS, HAL_DTS);
hal_dts_config_t cfg = { .reference_clock = HAL_DTS_REFERENCE_CLOCK_PCLK,
.quick_measurement = HAL_DTS_QUICK_MEASUREMENT_DISABLE,
.high_speed_clock_division = 0 };
hal_dts_sensor_config_t sensor_cfg = { .trigger = HAL_DTS_TRIGGER_SOFTWARE,
.sampling_time = HAL_DTS_SAMPLING_TIME_1_CYCLE };
HAL_DTS_SetConfig(&hDTS, &cfg);
HAL_DTS_SetConfigSensor(&hDTS, HAL_DTS_SENSOR_1, &sensor_cfg);
/* Configure thresholds (degC) using dedicated API */
HAL_DTS_SetSensorThresholds(&hDTS, HAL_DTS_SENSOR_1, 100, 10);
/* Enable low threshold optional interrupt */
HAL_DTS_StartSensor_IT_Opt(&hDTS, HAL_DTS_SENSOR_1, HAL_DTS_OPT_IT_LOW_THRESHOLD);
HAL_DTS_GetSensorTemperature(&hDTS, HAL_DTS_SENSOR_1, &temp);
HAL_DTS_StopSensor_IT(&hDTS, HAL_DTS_SENSOR_1);
|
Key changes ¶
HAL2 configures thresholds in degrees Celsius using
HAL_DTS_SetSensorThresholds().HAL2 enables optional threshold interrupts using
HAL_DTS_StartSensor_IT_Opt().
Use case: Wakeup from Stop/Sleep mode at end of measurement ¶
Sequence diagram ¶
Key changes ¶
HAL2 uses per-sensor interrupt start/stop APIs (
HAL_DTS_StartSensor_IT()andHAL_DTS_StopSensor_IT()).The HAL2 completion callback is consolidated as
HAL_DTS_CpltCallback.
Related examples in HAL2 ¶
|
Example name |
Brief |
|---|---|
|
example_hal_dts_wakeup_from_stop |
Perform and handle DTS temperature measurement with interrupt while CPU is in STOP mode. |







